package com.qishenyuan.competition.controller;


import com.qishenyuan.competition.common.Response;
import com.qishenyuan.competition.dto.CompetitionBriefReq;
import com.qishenyuan.competition.model.Competition;
import com.qishenyuan.competition.service.CompetitionService;
import com.qishenyuan.competition.vo.CompetitionBriefResp;
import com.qishenyuan.competition.vo.CompetitionDetailResp;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author qishenyuan
 * @since 2025-03-02
 */
@RestController
@RequestMapping("/competition")
public class CompetitionController {

    @Resource
    private CompetitionService competitionService;

    @RequestMapping("/getCompetitionList")
    public Response<List<CompetitionBriefResp>> getCompetitionList(@RequestBody @Validated CompetitionBriefReq competitionBriefReq){
        List<Competition> competitionList = competitionService.getCompetitionList(competitionBriefReq);
        List<CompetitionBriefResp> competitionBriefRespList = competitionList.stream()
                .map(CompetitionBriefResp::buildVo)
                .collect(Collectors.toList());
        return Response.ok(competitionBriefRespList);
    }

    @RequestMapping("/getCompetitionDetail")
    public Response<CompetitionDetailResp> getCompetitionDetail(@RequestBody @Validated CompetitionDetailResp competitionDetailResp){
        Competition competition = competitionService.getDetailById(competitionDetailResp.getId());
        return Response.ok(CompetitionDetailResp.buildVo(competition));
    }

}

